export default {
	namespaced:true,
	state:{
		list:[]
	},
	mutations:{
		add(state,payload){
			console.log(payload)
		let good=state.list.find(item=>item.goods_id===payload.goods_id)
		console.log(good)
		console.log(state.list)
		return	good?good.goods_count++:state.list.push(payload)
		},
		changeCount(state,payload){
			console.log(payload)
			let oldCount=state.list[payload.i].goods_count
			if (payload.count === -1 && oldCount === 1) return
			state.list[payload.i].goods_count+=payload.count
		},
		changeSingle(state,payload){
			console.log(payload)
			console.log(state.list[payload])
			return state.list[payload].goods_checked=!state.list[payload].goods_checked
		},
		switchAll(state,payload){
			console.log(payload)
			return	 state.list.forEach(item => {item.goods_checked = payload})
		},
		removeSelected(state){
			return	state.list = state.list.filter(it => !it.goods_checked)
		}
	}
}